package com.leecode;

/**
 * @Author: Aerospace
 * @Date: 2023/12/29 18:32
 * @Description: Dream begins
 */
public class TowSum {
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        int val = 0;
        int val1 = 0;
        if(l1 != null) val1 = l1.val;
        int val2 = 0;
        if(l2 != null) val2 = l2.val;
        if((val1+val2)>=10){
            val = val1+val2-10;
        }else{
            val = val1+val2;
        }
        ListNode l1next = l1!=null?l1.next:null;
        ListNode l2next = l2!=null?l2.next:null;
        if((val1+val2)>=10){
            if(l1next!=null){
                l1next = new ListNode(l1next.val++,l1next.next);
            }else{
                l2next = new ListNode(l2next.val++,l2next.next);
            }}
        if(l1next==null&&l2next==null){
            ListNode cur = new ListNode(val);
            return cur;
        }else{
            ListNode cur = new ListNode(val, addTwoNumbers(l1next, l2next));
            return cur;
        }

    }

    class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
   }

    public static void main(String[] args) {
        ListNode l1 = new ListNode(3,null);
    }
}
